package es.seam.myebay;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import es.seam.myebay.model.Auction;

@Name("auctionq")
@AutoCreate
public class AuctionQuery {

    @In(value = "entityManager")
    private EntityManager em;
    
    public Auction readAuction(int id) {
        Auction auction = (Auction) em.find(Auction.class, id);
        return auction;
    }
    
    public List<Auction> lastAuctions(int num) {
        String ejbql = "SELECT a FROM Auction a ORDER BY a.id DESC";
        Query query = em.createQuery(ejbql).setMaxResults(10);
        List<Auction> list = query.getResultList();
        return list;
    }
    
    public List<Auction> auctionsFromDate(Date from) {
        return null;
    }
    
}
